package com.jing.weibo.service.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.jing.weibo.mapper.user.UserInfoMapper;
import com.jing.weibo.pojo.UserInfo;

/**
 * 用户的Service
 * @author jing.yue
 * @version 2012/08/30 1.0.0
 */
@Component
public class UserInfoService {

	@Autowired
	private UserInfoMapper userInfoMapper;

	/**
	 * 根据用户名和用户类型查询用户对象
	 * @param userInfo
	 * @return
	 * @throws Exception
	 */
	public UserInfo findByUserName(UserInfo userInfo) throws Exception {
		// TODO Auto-generated method stub
		List<UserInfo> list = userInfoMapper.findByUserName(userInfo);
		if(list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	/**
	 * 根据用户名和用户类型修改用户信息
	 * @param userInfo
	 * @throws Exception
	 */
	@Transactional
	public void updateUserInfo(UserInfo userInfo) throws Exception {
		// TODO Auto-generated method stub
		userInfoMapper.updateUserInfo(userInfo);
	}


	/**
	 * 保存用户信息
	 * @param userInfo
	 * @throws Exception
	 */
	@Transactional
	public void saveUserInfo(UserInfo userInfo) throws Exception {
		userInfoMapper.saveUserInfo(userInfo);
	}

	/**
	 * 根据用户名和用户类型修改开启互粉状态
	 * @param userInfo
	 * @throws Exception
	 */
	public void updateUserInfoIsopenmp(UserInfo userInfo) throws Exception {
		// TODO Auto-generated method stub
		userInfoMapper.updateUserInfoIsopenmp(userInfo);
	}

	/**
	 * 根据用户名和类型获取参加了互粉的用户和在粉丝中不存在的前100个用户
	 * @param userInfo
	 * @return
	 * @throws Exception
	 */
	public List<UserInfo> findByJoinmpUserInfo(UserInfo userInfo) throws Exception {
		// TODO Auto-generated method stub
		return userInfoMapper.findByJoinmpUserInfo(userInfo);
	}

	/**
	 * 根据用户名和用户类型修改用户token过期时间
	 * @param userInfo
	 * @throws Exception
	 */
	public void updateUserInfoTokentime(UserInfo userInfo) throws Exception {
		// TODO Auto-generated method stub
		userInfoMapper.updateUserInfoTokentime(userInfo);
	}
}
